package com.agranee.timesheet.bean;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

import com.agranee.timesheet.service.LoginServiceImpl;

@ManagedBean(name="resetPasswordBean")
@RequestScoped
public class ResetPasswordBean {
	private String employeeId;
	private String newPassword;
	private String confirmPassword;
	
	private LoginServiceImpl loginService;
	
	
	
	public LoginServiceImpl getLoginService() {
		return loginService;
	}



	public void setLoginService(LoginServiceImpl loginService) {
		this.loginService = loginService;
	}



	public String getEmployeeId() {
		return employeeId;
	}



	public void setEmployeeId(String employeeId) {
		this.employeeId = employeeId;
	}



	public String getNewPassword() {
		return newPassword;
	}



	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}



	public String getConfirmPassword() {
		return confirmPassword;
	}



	public void setConfirmPassword(String confirmPassword) {
		this.confirmPassword = confirmPassword;
	}



	public void validateConfirmPassword(FacesContext facesContext,UIComponent uIComponent,Object value){
		 FacesMessage message = new FacesMessage();
         message.setSeverity(FacesMessage.SEVERITY_ERROR);
         message.setSummary("New Password and Confirm Password Doen't matches");
         message.setDetail("New Password and Confirm Password Doen't matches");
         facesContext.addMessage("New Password and Confirm Password Doen't matches", message);
         throw new ValidatorException(message);
	}
	
	public void resetPassword(){
		this.getLoginService().resetPasswordByEmployeeId(this.getEmployeeId(),this.getNewPassword());
	}

}
